using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Draw = System.Drawing;
using System.Windows.Forms;

namespace TayoukiNameSpace
{

    
    /// <summary>
    /// this would be useful if we were 
    /// resizing our images.  Not being used currently.
    /// </summary>
    public enum CollisionType { 
        Missed, 
        LeftEdge,
        RightEdge,
        TopEdge,
        BottomEdge,
        TopLeftCorner,
        TopRightCorner,
        BottomLeftCorner,
        BottomRightCorner
    };

    /// <summary>
    /// Use a shape interface so we could easily add new shapes to be
    /// created and dragged
    /// </summary>
    public interface IShape
    {
        /// <summary>
        /// Draws the shape to the grahics 
        /// </summary>
        /// <param name="pGraphics"></param>
        void Draw(Graphics pGraphics);

        /// <summary>
        /// Returns true if the mouse pointer is contained in the shape.
        /// </summary>
        /// <param name="pPoint"></param>
        /// <returns></returns>
        bool IsCollision(Point pPoint);

        /// <summary>
        /// Returns the icon to use to display for the mouse pointer
        /// </summary>
        /// <returns></returns>
        Cursor GetCursor();

        /// <summary>
        /// returns the upper left hand corner of the shape
        /// </summary>
        Point Location
        {
            get;
            set;
        }


        int shapeType
        {
            get;
            set;
        }

        /// <summary>
        /// returns true if the shape is being dragged.
        /// </summary>
        bool IsDragged
        {
            get;
            set;
        }

        /// <summary>
        /// returns true if the shape is selected.
        /// </summary>
        bool IsSelected
        {
            get;
            set;
        }

        /// <summary>
        /// brush to use to draw the image
        /// </summary>
        Brush Brush
        {
            get;
            set;
        }

        /// <summary>
        /// difference between the upper left hand corner of the shape
        /// and the mouse cursor.
        /// </summary>
        Point MouseOffset
        {
            get;
            set;
        }
    }
    /// <summary>
    /// Use a factory so that we could easily impliment having images on top of other
    /// using an variable "_order".  We could easily change the order and sort our
    /// shapes based on this order variable.  This is not implimented currently.
    /// </summary>
    public static class ShapeFactory
    {
        static int _order=0;

        /// <summary>
        /// returns a ShapeRectangle
        /// </summary>
        /// <param name="pLocation"></param>
        /// <param name="pSize"></param>
        /// <param name="pBrush"></param>
        /// <returns></returns>
        public static IShape Rectangle(Point pLocation, Size pSize, Brush pBrush, int pType)
        {

            ShapeRectangle lShapeRectangle=new ShapeRectangle(pLocation, pSize, pBrush, pType);
            lShapeRectangle.Order = _order;
            _order++;
            return lShapeRectangle;
            
        }
    }
    /// <summary>
    /// common implentation method and properties in a base class
    /// </summary>
    public abstract class Shape 
    {
        
        protected Point _pntMouseOffset;

        /// <summary>
        /// The offset between the left upper corner of the shape
        /// and the mouse pointer.
        /// </summary>
        public Point MouseOffset
        {
            get { return _pntMouseOffset; }
            set { _pntMouseOffset = value; }
        }
	
        protected int _order;
        protected Cursor _cursor;

        /// <summary>
        /// order in which to draw the image.
        /// Not currently used.
        /// </summary>
        public int Order
        {
            get { return _order; }
            set { _order = value; }
        }
	

        protected bool _blnIsDragged;

        /// <summary>
        /// returns true if the image is being dragged.
        /// </summary>
        public virtual bool IsDragged
        {
            get { return _blnIsDragged; }
            set { _blnIsDragged = value; }
        }

        protected  bool _blnIsSelected;

        /// <summary>
        /// returns true if the image is selected.
        /// </summary>
        public virtual bool IsSelected
        {
            get { return _blnIsSelected; }
            set { _blnIsSelected = value; }
        }

        protected Point _pntLocation;
        /// <summary>
        /// returns the upper left hand point of the shape.
        /// </summary>
        public virtual Point Location
        {
            get { return _pntLocation; }
            set { _pntLocation = value; }
        }


        protected int _shapeType;

        public virtual int shapeType
        {
            get { return _shapeType; }
            set { _shapeType = value; }
        }

        protected  Pen _pen;
        /// <summary>
        /// drawing pen
        /// </summary>
        public virtual Pen Pen
        {
            get { return _pen; }
            set { _pen = value; }
        }

        protected  Brush _brush;
        /// <summary>
        /// drawing brush
        /// </summary>
        public virtual Brush Brush
        {
            get { return _brush; }
            set { _brush = value; }
        }

       /// <summary>
       /// returns the cursor to use for the mouse.
       /// </summary>
       /// <returns></returns>
        public virtual Cursor GetCursor()
        {
            return this._cursor;
        }
        

        #region IShape Members

       
        #endregion
    }

    /// <summary>
    /// Rectangle Shape
    /// </summary>
    public class ShapeRectangle : Shape,IShape
    {
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="pLocation"></param>
        /// <param name="pSize"></param>
        /// <param name="pBrush"></param>
        /// 

        public int iShapeType;

        public ShapeRectangle(Point pLocation, Size pSize, Brush pBrush,int pType)
        {
            _rectRegion = new Rectangle(pLocation, pSize);
            _brush = pBrush;
            _shapeType = pType;
        }

        /// <summary>
        /// Prevent them from using the default constructor
        /// </summary>
        private ShapeRectangle() { }


        private Draw.Rectangle _rectRegion;
       
        /// <summary>
        /// defines where and how big the rectangle should be
        /// </summary>
        public Draw.Rectangle RectRegion
        {
            get { return _rectRegion; }
            set { _rectRegion = value; }
        }

        

        #region IShape Members
       
        /// <summary>
        /// Draw the rectangle to the graphics
        /// </summary>
        /// <param name="pGraphics"></param>
        void IShape.Draw(Graphics pGraphics)
        {
            Point[] points = { new Point(10, 10), new Point(100, 10), new Point(50, 100) };
            //pGraphics.FillRectangle(_brush, _rectRegion);
           // pGraphics.FillEllipse(_brush,_rectRegion);
            

            if (_shapeType == 1)//rectangle
            {
                pGraphics.FillRectangle(_brush, _rectRegion);
            }
            if (_shapeType == 2)//circle
            {
                pGraphics.FillEllipse(_brush, _rectRegion);
            }
            if (_shapeType == 4)//Big circle
            {
                pGraphics.FillEllipse(_brush, _rectRegion);
            }
            if (_shapeType == 3)//pie
            {
                pGraphics.FillPie(_brush, _rectRegion, 60, 60);
            }

        }
        /// <summary>
        /// returns true if the mouse pointer is inside the shape
        /// </summary>
        /// <param name="pPoint"></param>
        /// <returns></returns>
        bool IShape.IsCollision(Point pPoint)
        {
            // determine type of collision

            /*
             * For now just see if there is any kind of collision
             * with the cursor
             */
            Rectangle lrectCursorRect=new Rectangle(pPoint,new Size(2,2));
            if (this._rectRegion.IntersectsWith(lrectCursorRect))
            {
                this._cursor = Cursors.SizeAll;
                return true;
            }
           
            return false;
        }

        /// <summary>
        /// location of the upper left hand corner of the shape.
        /// </summary>
        override public Point Location
        {
            get
            {
                return _rectRegion.Location;
            }
            set
            {
                /*
                 * use the mouse offset so that the image upper left hand
                 * corner does not jump to the mouse location.
                 */
                _rectRegion.Location = new Point(value.X + this.MouseOffset.X, value.Y + this.MouseOffset.Y);
            }
        }


        

        #endregion





       
    }
}
